package com.example.zzm.yuejian03.Fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.zzm.yuejian03.Activity.ActivActivity;
import com.example.zzm.yuejian03.Activity.MasterActivity;
import com.example.zzm.yuejian03.Activity.MatchActivity;
import com.example.zzm.yuejian03.Activity.sousuoActivitiy;
import com.example.zzm.yuejian03.Bean.Lunbotu;
import com.example.zzm.yuejian03.Listener.LunboListrence;
import com.example.zzm.yuejian03.Model.LunboModel;
import com.example.zzm.yuejian03.R;
import com.example.zzm.yuejian03.Server;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends BaseFragment{

    private ImageView imageView5,imageView6,imageView7;
    private EditText editText7;
    private Button button31;
    private View view;
    private Banner banner;
    @Override
    void initView() {
        imageView5 = (ImageView)view.findViewById(R.id.imageView5);
        imageView6 = (ImageView)view.findViewById(R.id.imageView6);
        imageView7 = (ImageView)view.findViewById(R.id.imageView7);
        editText7 = (EditText)view.findViewById(R.id.editText7);
        button31 = (Button)view.findViewById(R.id.button31);
        banner = (Banner)view.findViewById(R.id.banner);
    }

    @Override
    void initEvent() {

        imageView5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getActivity(), ActivActivity.class));
                //getActivity().onBackPressed();
            }
        });
        imageView7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getActivity(), MasterActivity.class));
                //getActivity().onBackPressed();
            }
        });
        imageView6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getActivity(), MatchActivity.class));
                //getActivity().onBackPressed();
            }
        });
        button31.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(),sousuoActivitiy.class));
            }
        });
    }

    @Override
    void initData() {

    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view= inflater.inflate(R.layout.fragment_home,container,false);
        initData();
        initView();
        initEvent();
        LunboModel bannerModel = new LunboModel();
        bannerModel.getLubbo(listener);
        return  view;
    }

    LunboListrence listener = new LunboListrence() {
        @Override
        public void onResponse(List<Lunbotu> beanlist) {

            Lunbotu hBanner;
            ArrayList<String> list_pic = new ArrayList<String>();
            for (int i = 0;i< beanlist.size();i++){
                hBanner = beanlist.get(i);
                list_pic.add(Server.IMAGEURL+hBanner.getPic()) ;
            }
            initbanner(list_pic);
        }

        @Override
        public void onFail(String msg) {
        }
    };

    public void initbanner(List list_path){
        //设置内置样式，共有六种可以点入方法内逐一体验使用。
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        //设置图片加载器，图片加载器在下方
        banner.setImageLoader(new MyLoader());
        //设置图片网址或地址的集合
        banner.setImages(list_path);
        //设置轮播的动画效果，内含多种特效，可点入方法内查找后内逐一体验
        banner.setBannerAnimation(Transformer.Default);
        //设置轮播图的标题集合
        // banner.setBannerTitles(list_title);
        //设置轮播间隔时间
        banner.setDelayTime(3000);
        //设置是否为自动轮播，默认是“是”。
        banner.isAutoPlay(true);
        //设置指示器的位置，小点点，左中右。
        banner.setIndicatorGravity(BannerConfig.CENTER)
                //以上内容都可写成链式布局，这是轮播图的监听。比较重要。方法在下面。
                .setOnBannerListener(new OnBannerListener() {
                    @Override
                    //轮播图的监听方法
                    public void OnBannerClick(int position) {
                        Log.i("tag", "你点了第"+position+"张轮播图");
                    }
                })
                //必须最后调用的方法，启动轮播图。
                .start();
    }
    //自定义的图片加载器
    private class MyLoader extends ImageLoader {
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Glide.with(context).load((String) path).into(imageView);
        }
    }
    public interface OnFragmentInteractionListener {
    }
}

